﻿using BaseData.API.Write.Applications.DoctorScheduling.Command;
using BaseData.ErrorCode;
using BaseData.Infrastructure.Interfaces;
using BaseData.Domain.DoctorScheduling;
using MediatR;
using AutoMapper;

namespace BaseData.API.Write.Applications.DoctorScheduling.CommandHandler
{
    public class AddDoctorSchedulingCommandHandler : IRequestHandler<AddDoctorSchedulingCommand, ApiResult<int>>
    {
        private readonly IBaseRepository<Scheduling> baseRepository;
        private readonly IMapper mapper;

        public AddDoctorSchedulingCommandHandler(IBaseRepository<Scheduling> baseRepository, IMapper mapper)
        {
            this.baseRepository = baseRepository;
            this.mapper = mapper;
        }

        public async Task<ApiResult<int>> Handle(AddDoctorSchedulingCommand request, CancellationToken cancellationToken)
        {
            ApiResult<int> result = new ApiResult<int>();
            result.Code = ApiEnum.添加成功;
            result.Message = ApiEnum.添加成功.ToString();
            var schduling = mapper.Map<Scheduling>(request);
            await baseRepository.AddAsync(schduling);
            return await Task.FromResult(result);
        }
    }
}
